import  time
import  xlrd
from  xlutils import  copy

while 1:
    time.sleep(2)
    a=open(r'C:\Users\杨宇博\Desktop\b.log','r',encoding='utf-8').read()
    b=a.split('\n\n')
    SUM = []
    I = 0
    W = 0
    V = 0
    E = 0
    c = 0
    for i in b:
        if i[0]=="I":
            I += 1
        elif i[0] == "W":
            W += 1
        elif i[0]== "V":
            V += 1
        elif i[0]== "E":
            E += 1
        else:
            c+=1
    SUM.append([I, W, V, E,c])
    print(SUM)
    wb = xlrd.open_workbook("数据统计表.xls")
    wb_copy = copy.copy(wb)
    ws_copy = wb_copy.get_sheet(0)
    for i in range(0, len(b)):
        ws_copy.write(i + 1, 0, I)
        ws_copy.write(i + 1, 1, W)
        ws_copy.write(i + 1, 2, V)
        ws_copy.write(i + 1, 3, E)
        ws_copy.write(i + 1, 4, c)
    wb_copy.save("数据统计表1.xls")
    print('--------------------------')